package com.tianzeculture.stagebao.activity.artist;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.PersonnelPoolBean;
import com.tianzeculture.stagebao.bean.User;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.network.util.ToastUtil;
import com.tianzeculture.stagebao.popwindow.RangePickerPopWindow;
import com.tianzeculture.stagebao.util.StatusBarUtil;
import com.tianzeculture.stagebao.util.Util;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/4 0004.
 * 加入人才库-编辑艺人资料
 */

public class ArtistEditDataActivity extends BaseActivity
        implements RangePickerPopWindow.RangePickListener {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvRight)
    TextView tvRight;
    @BindView(R.id.layout_root)
    RelativeLayout rootLayout;

    @BindView(R.id.layoutHeight)
    LinearLayout layoutHeight;
    @BindView(R.id.layoutWeight)
    LinearLayout layoutWeight;
    //    @BindView(R.id.layoutBust)
//    LinearLayout layoutBust;
//    @BindView(R.id.layoutWaist)
//    LinearLayout layoutWaist;
//    @BindView(R.id.layoutHipline)
//    LinearLayout layoutHipline;
    @BindView(R.id.layoutShoeSize)
    LinearLayout layoutShoeSize;

    @BindView(R.id.tvHeight)
    EditText tvHeight;
    @BindView(R.id.tvWeight)
    EditText tvWeight;
    //    @BindView(R.id.tvBust)
//    EditText tvBust;
//    @BindView(R.id.tvWaist)
//    EditText tvWaist;
//    @BindView(R.id.tvHipline)
//    EditText tvHipline;
    @BindView(R.id.tvShoeSize)
    EditText tvShoeSize;

    User myUser = null;


    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
        tvTitle.setText("个人资料");
        tvRight.setText("确定");
        tvRight.setVisibility(View.VISIBLE);
        myUser = (User) getIntent().getSerializableExtra("user");
        initUser();
    }

    private void initUser() {
        tvHeight.setText(myUser.getUserHeight() == null ? "" : myUser.getUserHeight());
        tvWeight.setText(myUser.getUserWeight() == null ? "" : myUser.getUserWeight());
        tvShoeSize.setText(myUser.getShoeSize() == null ? "" : myUser.getShoeSize());
    }

    /**
     * 非空判断
     */
    private boolean isEmpty() {
        if ("".equals(tvHeight.getText().toString().trim())) {
            ToastUtil.showShort(this, "身高不能为空!");
            return false;
        } else if ("".equals(tvWeight.getText().toString().trim())) {
            ToastUtil.showShort(this, "体重不能为空!");
            return false;

        } else if ("".equals(tvShoeSize.getText().toString().trim())) {
            ToastUtil.showShort(this, "年龄不能为空!");
            return false;
        }

        return true;
    }

    @OnClick({R.id.tvRight, R.id.layoutHeight, R.id.layoutWeight, R.id.layoutShoeSize})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvRight:
                if (isEmpty()) {
                    myUser.setUserHeight(tvHeight.getText().toString().trim());
                    myUser.setUserWeight(tvWeight.getText().toString().trim());
                    myUser.setShoeSize(tvShoeSize.getText().toString().trim());
                    Intent intent = new Intent();
                    intent.putExtra("user", myUser);
                    setResult(Util.EDIT_ARTIST_BASIC, intent);
                    PersonnelPoolBean bean = new PersonnelPoolBean();
                    bean.setType(1);
                    bean.setUserHeight(tvHeight.getText().toString().trim());
                    bean.setUserWeight(tvWeight.getText().toString().trim());
                    bean.setShoeSize(tvShoeSize.getText().toString().trim());
                    EventBus.getDefault().post(bean);
                    finish();
                }
                break;
//            case R.id.layoutHeight:
//                type = 1;
//                int[] heights = {0, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
//                        178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
//                        190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202};
//                RangePickerPopWindow rangePickerPopWindow = new RangePickerPopWindow(this, heights, false);
//                rangePickerPopWindow.setCityPickListener(this);
//                rangePickerPopWindow.showPopupWindow(rootLayout);
//                break;
//            case R.id.layoutWeight:
//                type = 2;
//                int[] weight = {0, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
//                        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
//                        64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80};
//                RangePickerPopWindow rangePickerPopWindow2 = new RangePickerPopWindow(this, weight, false);
//                rangePickerPopWindow2.setCityPickListener(this);
//                rangePickerPopWindow2.showPopupWindow(rootLayout);
//                break;
//            case R.id.layoutBust:
//                type = 3;
//                int[] busts = {0, 70, 71, 72, 73, 74, 75, 76, 77, 78, 125, 130, 135,
//                        140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195,
//                        200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260};
//                RangePickerPopWindow rangePickerPopWindow3 = new RangePickerPopWindow(this, busts, false);
//                rangePickerPopWindow3.setCityPickListener(this);
//                rangePickerPopWindow3.showPopupWindow(rootLayout);
//                break;
//            case R.id.layoutWaist:
//                type = 4;
//                int[] waist = {0, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135,
//                        140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195,
//                        200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260};
//                RangePickerPopWindow rangePickerPopWindow4 = new RangePickerPopWindow(this, waist, false);
//                rangePickerPopWindow4.setCityPickListener(this);
//                rangePickerPopWindow4.showPopupWindow(rootLayout);
//                break;
//            case R.id.layoutHipline:
//                type = 5;
//                int[] hipline = {0, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135,
//                        140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195,
//                        200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260};
//                RangePickerPopWindow rangePickerPopWindow5 = new RangePickerPopWindow(this, hipline, false);
//                rangePickerPopWindow5.setCityPickListener(this);
//                rangePickerPopWindow5.showPopupWindow(rootLayout);
//                break;
//            case R.id.layoutShoeSize:
//                type = 6;
//                int[] shoeSize = {0, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135,
//                        140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195,
//                        200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260};
//                RangePickerPopWindow rangePickerPopWindow6 = new RangePickerPopWindow(this, shoeSize, false);
//                rangePickerPopWindow6.setCityPickListener(this);
//                rangePickerPopWindow6.showPopupWindow(rootLayout);
//                break;
//
        }
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_edit_data;
    }

    int type = 0;//0未选 1身高 2体重 3胸围 4腰围 5臀围 6鞋码

    @Override
    public void pickValue(String value) {
        switch (type) {
            case 1:
                tvHeight.setText(value);
                break;
            case 2:
                tvWeight.setText(value);
                break;
//            case 3:
//                tvBust.setText(value);
//                break;
//            case 4:
//                tvWaist.setText(value);
//                break;
//            case 5:
//                tvHipline.setText(value);
//                break;
            case 6:
                tvShoeSize.setText(value);
                break;
        }
    }
}
